#include "TitleMenuState.h"
#include "OptionsMenuState.h"
#include "MainMenuState.h"
#include "Game.h"
#include "BitmapFont.h"
#include "CSGD_Direct3D.h"
#include "CSGD_TextureManager.h"
#include "CSGD_DirectInput.h"
#include "CSGD_XAudio2.h"
#include "../resource.h"

/////////////////////////////////////////////////////////////////////////////
// Function		: CMainMenuState
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CTitleMenuState::CTitleMenuState(void)
{
	m_nCursor = 0;
	m_nBackgroundImg = -1;
	m_nTitleImage = -1;
}

/////////////////////////////////////////////////////////////////////////////
// Function		: ~CMainMenuState
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CTitleMenuState::~CTitleMenuState(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// Function		: GetInstance
// Return		: CMainMenuState* 
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CTitleMenuState* CTitleMenuState::GetInstance( void )
{
	static CTitleMenuState s_Instance;

	return &s_Instance;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Enter
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CTitleMenuState::Enter( void )
{
	m_nBackgroundImg = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/Background.png"));
	m_nTitleImage = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/tuglogo.png"));

	if(COptionsMenuState::GetInstance()->ReturnEng())
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_PrsAnyKey, PrsAnyKey, 40);
	else
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_PrsAnyKey, PrsAnyKey, 40);

	for (int character = 0; character < 40; character++)
	{
		if(PrsAnyKey[character] != NULL)
			TrueAnyKey += (char)PrsAnyKey[character];
		else
			break;
	}
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Exit
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CTitleMenuState::Exit ( void )
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(m_nBackgroundImg);
	CSGD_TextureManager::GetInstance()->UnloadTexture(m_nTitleImage);
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Input
// Return		: bool
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
bool CTitleMenuState::Input( void )
{
	CSGD_DirectInput* m_pDI = CSGD_DirectInput::GetInstance();
	
	if(CSGD_DirectInput::GetInstance()->CheckKeys() != 0 || m_pDI->JoystickButtonPressed(0,0))
	{
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
		CSGD_XAudio2::GetInstance()->SFXPlaySound(CGame::GetInstance()->GetMenuMovID());
	}
	return true;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Update
//Parameters	: fElapsedTime - The ammount of time that has passed since last update
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CTitleMenuState::Update( float fElapsedTime )
{

}
/////////////////////////////////////////////////////////////////////////////
// Function		: Render
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CTitleMenuState::Render( void )
{
	CSGD_TextureManager::GetInstance()->Draw(m_nBackgroundImg,0,0);

	CSGD_TextureManager::GetInstance()->Draw(m_nTitleImage,-16,-128, 0.8f, 0.8f);

	CBitmapFont* font = CGame::GetInstance()->GetFont();

	font->Draw(PrsAnyKey, CGame::GetInstance()->GetScreenWidth()/2 -(CGame::GetInstance()->GetFont()->GetStringWidth(TrueAnyKey,1.0f)/2), 
		CGame::GetInstance()->GetScreenHeight() - CGame::GetInstance()->GetFont()->GetWidth() - 10, 1.0f, D3DCOLOR_ARGB(255,255,0,0));
}		